package sv;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class WelcomeWindow extends JFrame implements ActionListener{
	private Pan panel;
	private Image image;
	private JButton ris,test;
	
	public WelcomeWindow(){
		/*try{
			image = ImageIO.read(new File("Immagini/sfondo.png"));
		}
		catch(java.lang.OutOfMemoryError ex){}
		catch(IOException v){}*/
		
		URL url = getClass().getResource("Immagini/sfondo.png");
		//System.out.println(url);
		image = Toolkit.getDefaultToolkit().getImage( url );
		
		setTitle("Sudoku solver");
		setSize(500, 500);
		setIconImage(image);

		panel = new Pan();
		panel.setLayout(null);
		
		ris=new JButton("Risolvi");
		ris.addActionListener(this);
		ris.setBounds(5,275,140,40);
		panel.add(ris);
		
		test=new JButton("Test");
		test.addActionListener(this);
		test.setBounds(340,275,140,40);
		panel.add(test);
		
		add(panel);		
		
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		setResizable(false);
		setVisible(true);
	}
	
	class Pan extends JPanel{
		public void paintComponent(Graphics g){
			super.paintComponent(g);
			Graphics2D g2 = (Graphics2D)g; 
			
			setBackground(Color.white);
			g2.drawImage(image,90,90,this);
			
			g.setColor(Color.red);
			g.setFont(new Font("TimesRoman",Font.PLAIN,100));
			g.drawString("Sudoku",90,80);
			g.setFont(new Font("TimesRoman",Font.ITALIC,100));
			g.drawString("solver",120,450);
		}
	}
	
	public void actionPerformed (ActionEvent e){
		Object source= e.getSource();
		dispose();
		if(source==ris){
			WelcomeTable wt = new WelcomeTable(image,this);
		}
		if(source==test){
			//ToolBox tb = new ToolBox(SudokuGames.get(0),true);
			//for(int i=0;i<3;i++){
				//SolverManager sm = new SolverManager(this);
			SolverChoose sc = new SolverChoose(this);
				
			//}
			//SolverRule sr=new SolverRule( 1, true);
			
		}
	}
}

class Test{
	public static void main(String[] args){
		WelcomeWindow wWindow = new WelcomeWindow();
	}
}
